package main

import "fmt"

// interface本质是一个指针
type Animal interface {
	Sleep()
	GetColor() string //获取颜色
	GetType() string  //获取种类
}

// 具体的类，通过实现interface的3个方法来实现多态
type Cat struct {
	color string
}

func (this *Cat) Sleep() {
	fmt.Println("Cat is sleep")
}

func (this *Cat) GetColor() string {
	return this.color
}

func (this *Cat) GetType() string {
	return "Cat"
}

type Dog struct {
	color string
}

func (this *Dog) Sleep() {
	fmt.Println("Dog is sleep")
}

func (this *Dog) GetColor() string {
	return this.color
}

func (this *Dog) GetType() string {
	return "Dog"
}

func showAnimal(animal Animal) {
	animal.Sleep()
	fmt.Println("animal color is", animal.GetColor())
	fmt.Println("animal type is", animal.GetType())
}
func main() {
	var animal Animal // 接口数据类型，是一个父类指针
	animal = &Cat{"white"}
	animal.Sleep()

	var animal2 Animal
	animal2 = &Dog{"yellow"}
	showAnimal(animal2)
}
